﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraBars.Localization;
using DevExpress.XtraTab;

namespace RapChieuPhim
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            initSkinsHelp();
            ShowHideControl(true, 5);
            ribbon.SelectedPage = ribPageTrangChinh;

            Modules.About _About = new Modules.About();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabAbout", "About", _About);
        }


        #region init All
        private void initSkinsHelp()
        {
            BarLocalizer.Active = new MyBarLocalizer();
            SkinHelper.InitSkinGallery(ribbonGalleryBarItem1, true);
        }

        public class MyBarLocalizer : BarLocalizer
        {
            public override string GetLocalizedString(BarString id)
            {
                if (id == BarString.SkinCaptions)
                {
                    string defaultSkinCaptions = base.GetLocalizedString(id);
                    string newSkinCaptions = defaultSkinCaptions.Replace("|DevExpress Style|", "|My Favorite Skin|");
                    return newSkinCaptions;
                }
                return base.GetLocalizedString(id);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            labelTime.Caption = DateTime.Now.ToString();
        }

        private void TabControlMain_ControlAdded(object sender, ControlEventArgs e)
        {
            TabControlMain.SelectedTabPageIndex = TabControlMain.TabPages.Count - 1;
        }

        private void TabControlMain_CloseButtonClick(object sender, EventArgs e)
        {
            if (TabControlMain.SelectedTabPageIndex != 0)
                TabControlMain.TabPages.RemoveAt(TabControlMain.SelectedTabPageIndex);
        }
        #endregion

        #region Show/Hide Controls
        private void ShowHideControl(Boolean _flag, int _typeOfLogin)
        {
            if (_flag)
            {
                switch (_typeOfLogin)
                {
                    case 0:
                        ResetShowHide();
                        ribPageAccount.Visible = _flag;
                        PageGroupAccAdmin.Visible = _flag;
                        PageGroupHoTroGiaiDap.Visible = _flag;
                        ribbon.SelectedPage = ribPageAccount;
                        labelInfoAcc.Caption = "Chào, admin";
                        break;
                    case 1:
                        ResetShowHide();
                        ribPageTruongBP.Visible = _flag;
                        ribPageAccount.Visible = _flag;
                        PageGroupAccTruong.Visible = _flag;
                        PageGroupHoTroGiaiDap.Visible = _flag;
                        ribbon.SelectedPage = ribPageTruongBP;
                        labelInfoAcc.Caption = "Chào, Trưởng BP: Trần Thanh Long";
                        break;
                    case 2:
                        ResetShowHide();
                        ribPageQLRap.Visible = _flag;
                        ribPageAccount.Visible = _flag;
                        PageGroupAccNhanVien.Visible = _flag;
                        PageGroupHoTroGiaiDap.Visible = _flag;
                        ribbon.SelectedPage = ribPageQLRap;
                        labelInfoAcc.Caption = "Chào, Quản lí: Hoàng Hoa Thám";
                        break;
                    case 3:
                        ResetShowHide();
                        ribPageBanVe.Visible = _flag;
                        ribPageAccount.Visible = _flag;
                        PageGroupAccNhanVien.Visible = _flag;
                        PageGroupHoTroGiaiDap.Visible = _flag;
                        ribbon.SelectedPage = ribPageBanVe;
                        labelInfoAcc.Caption = "Chào, Nhân viên: Nguyễn Thị Lượm";
                        break;
                    case 4:
                        ResetShowHide();
                        ribPageAccount.Visible = _flag;
                        PageGroupAccCard.Visible = _flag;
                        ribPageDatVe.Visible = _flag;
                        PageGroupHoTroThacMac.Visible = _flag;
                        ribbon.SelectedPage = ribPageDatVe;
                        labelInfoAcc.Caption = "Chào mừng đã trở lại, Thành viên: Kiều Thư";
                        break;
                    case 5:
                        ResetShowHide();
                        ribPageDatVe.Visible = _flag;
                        PageGroupHoTroThacMac.Visible = _flag;
                        ribbon.SelectedPage = ribPageDatVe;
                        labelInfoAcc.Caption = "Chào bạn. Nay trời đẹp chứ :)";
                        break;
                }
            }
            else
            {
                Application.Restart();
            }
        }

        private void ResetShowHide()
        {
            ribPageAccount.Visible = false;
            ribPageTruongBP.Visible = false;
            ribPageQLRap.Visible = false;
            ribPageBanVe.Visible = false;
            ribPageDatVe.Visible = false;
            PageGroupAccAdmin.Visible = false;
            PageGroupAccTruong.Visible = false;
            PageGroupAccNhanVien.Visible = false;
            PageGroupAccCard.Visible = false;
            PageGroupHoTroThacMac.Visible = false;
            PageGroupHoTroGiaiDap.Visible = false;
        }

        private void barButtonLogout_ItemClick(object sender, ItemClickEventArgs e)
        {
            ResetShowHide();
        }

        private void btnLogAsAdmin_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowHideControl(true, 0);
        }

        private void btnLogAsTruongBP_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowHideControl(true, 1);
        }

        private void btnLogAsQL_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowHideControl(true, 2);
        }

        private void btnLogAsNV_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowHideControl(true, 3);
        }

        private void btnLogAsMember_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowHideControl(true, 4);
        }

        private void btnLogout_ItemClick(object sender, ItemClickEventArgs e)
        {
            barButtonLogout_ItemClick(null, null);
        }
        #endregion

        #region Show Tab for Page 'Trang chính'
        private void barButtonAccAdmin_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }

        private void barButtonLogin_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.Login _Login = new Modules.Login();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabLogin", "Đăng nhập", _Login);
        }

        private void barButtonMap_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.ApplicationMap _ApplicationMap = new Modules.ApplicationMap();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabMap", "Application Map", _ApplicationMap);
        }

        private void barButtonAbout_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.About _About = new Modules.About();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabAbout", "About", _About);
        }

        private void barButtonHelp_ItemClick(object sender, ItemClickEventArgs e)
        {

        }
        #endregion

        #region Show Tab for Page 'Thông tin tài khoản'
        private void barButtonAllAcc_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.AccAgent _AccAgent = new Modules.AccAgent();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabAccAgent", "Tài khoản nhân viên", _AccAgent);
        }

        private void barButtonInfoNV_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.InfoAllAgent _InfoAllAgent = new Modules.InfoAllAgent();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabInfoAllAgent", "Danh sách nhân viên", _InfoAllAgent);
        }

        private void barButtonAccCard_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.MemberCard _MemberCard = new Modules.MemberCard();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabMemberCard", "Thông tin thẻ", _MemberCard);
        }
        #endregion

        private void barButtonTruongRap_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.ListCinema _ListCinema = new Modules.ListCinema();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabListCinema", "Danh sách các rạp", _ListCinema);
        }

        private void barButtonTruongPhongChieu_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void barButtonDatVeInfoPhim_ItemClick(object sender, ItemClickEventArgs e)
        {
            GUI.InfoMovie _InfoMovie = new GUI.InfoMovie();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabInfoMovie", "Thông tin phim", _InfoMovie);
        }

        private void barButtonBanVe_ItemClick(object sender, ItemClickEventArgs e)
        {

        }


    }
}